package com.e.library.utils;

import android.text.TextUtils;
import android.view.animation.Animation;
import android.view.animation.CycleInterpolator;
import android.view.animation.TranslateAnimation;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by lxy on 2016/5/9.
 */
public class EUtils {

    /**
     *
     * @param list
     * @author lxy
     */
    public static boolean isEmpty(List<?> list){
        return list == null || list.isEmpty();
    }

    /**
     * 验证是否为手机号码
     * @param mobiles
     * @return
     */
    public static boolean isMobile(String mobiles){
        if (TextUtils.isEmpty(mobiles)) {
            return false;
        }
        Pattern p = Pattern.compile("^((13[0-9])|(14[0-9])|(15[^4,\\D])|(17[0-9])|(19[0-9])|(18[0-9]))\\d{8}$");
        Matcher m = p.matcher(mobiles);
        return m.matches();
    }

    public static Animation shakeAnimation() {
        return shakeAnimation(2);
    }

    /**
     * 晃动动画
     * @param counts 1秒钟晃动多少下
     * @return
     */
    public static Animation shakeAnimation(int counts) {
        Animation translateAnimation = new TranslateAnimation(0, 10, 0, 0);
        translateAnimation.setInterpolator(new CycleInterpolator(counts));
        translateAnimation.setDuration(1000);
        return translateAnimation;
    }


}
